﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Delonix_Regia_Hotel_Management_System.Class;

namespace Delonix_Regia_Hotel_Management_System
{
    public partial class Room_Functions : Form
    {
        public Room_Functions()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (LogInClass.position == "Administrator")
            {
                Main__Management_and_Administrator_ mainA = new Main__Management_and_Administrator_();
                this.Hide();
                mainA.Show();
            }
            else
            {
                Main__Receptionist_ mainR = new Main__Receptionist_();
                this.Hide();
                mainR.Show();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Form1 F = new Form1();
            this.Hide();
            F.Show(); 
        }

        private void btnCA_Click(object sender, EventArgs e)
        {
            string enqStartDate = DTP1.Value.ToString("dd/MM/yyyy");
            DateTime startDate = Convert.ToDateTime(enqStartDate);
            string enqEndDate = Convert.ToString(DTP2.Value);
            DateTime endDate = Convert.ToDateTime(enqEndDate);
            int compareDate = DateTime.Compare(startDate, endDate);
            string enqRoomType = Convert.ToString(comboBoxRoomType.SelectedItem);
            Room roomAvailable = new Room();

            if (startDate.CompareTo(DateTime.Now) < 0)
            {
                MessageBox.Show("Sorry, the Check-In Date cannot be earlier than today's date (" + DateTime.Now.ToString() + ")");
                return;
            }

            else if (compareDate < 0)
            {
                if (DBManager.CheckRoomAvailability(enqStartDate, enqEndDate, enqRoomType) != null)
                {
                    string message = "The current enquiry date is available! Do you want to proceed to the booking page?";
                    string caption = "Check Room Availability";
                    MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                    DialogResult result;

                    result = MessageBox.Show(message, caption, buttons);

                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        Room_Booking roomBooking = new Room_Booking();
                        this.Hide();
                        roomBooking.Show();
                    }


                }
                else
                {
                    lblStatus.Text = "Sorry! The current enquiry date is unavailable!";
                }
            }
            else
            {
                lblStatus.Text = "Sorry! The check out date must not be earlier than the check in date.";
            }

        }

        private void btnUpdateInfo_Click(object sender, EventArgs e)
        {
            CuustomerInformation custInfo = new CuustomerInformation();
            this.Hide();
            custInfo.Show();
        }

        private void btnCheckout_Click(object sender, EventArgs e)
        {
            PaymentCheckOut checkout = new PaymentCheckOut();
            this.Hide();
            checkout.Show();
        }
    }
}
